<template>
    <div class="mine">
        <!-- 登录后显示页面 -->
        <div class="isLogin" v-if="loginIn">
            <div class="album-top">
                <router-link to="upload">
                    <div class="album-img">
                        <img :src="avator" />
                    </div>
                </router-link>
                <div class="album-info">
                    <span class="info-name">{{ username }}</span>
                    <span class="info-sex">{{ userSex }} |</span>
                    <span class="info-birth">{{ birth }} |</span>
                    <span class="info-location">{{ location }} |</span>
                    <span class="info-signature">{{ introduction }}</span>
                </div>
                <router-link to="/info"><div class="mui-icon mui-icon-compose logout"></div></router-link>
            </div>
            <div class="album-content">
                <p class="album-content-title">我的收藏</p>
                <div class="songs-body">
                    <album-content :songList="collectList"> </album-content>
                </div>
            </div>
        </div>
        <!-- 未登录显示页面 -->
        <div v-else>
            <div class="member">
                <div class="header-con">
                    <router-link to="/login-in">
                        <div class="user-info">
                            <div class="avatar-con">
                                <div class="avatar">
                                    <img
                                            src="/src/assets/is-play.gif"
                                            class="image-info"
                                            alt=""
                                    />
                                </div>
                            </div>
                            <div class="person-con">
                                <span> 登录 / 注册</span>
                            </div>
                        </div>
                    </router-link>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    // eslint-disable-next-line no-unused-vars
    import  axios from 'axios'
    import { mixin } from "../minx";
    // eslint-disable-next-line no-unused-vars
    import { mapGetters } from "vuex";
    // eslint-disable-next-line no-unused-vars
    import { getUserOfId, getCollectOfUserId, songOfSongId } from "../utils/index";
    // eslint-disable-next-line no-unused-vars
    import AlbumContent from "../components/AlbumContent";
    export default {
        name: "Mine",
        mixins: [mixin],
        //导入组件
        components:{
            AlbumContent,
        },
        //  进入页面自动加载
        mounted() {
            this.getMsg(this.userId);
            this.getCollection(this.userId);
        },
        //参数
        data(){
            return {
                avator: "", //用户头像
                username: "", //昵称
                userSex: "", //性别
                birth: "", //生日
                location: "", //故乡
                introduction: "", //签名
                collection: [], //收藏的歌曲列表
                collectList: [], //收藏的歌曲列表（带歌曲详情）
            };
        },
        // 调用vuex里面的参数
        computed: {
            ...mapGetters([
                "listOfSongs", //当前播放列表
                "userId", //当前登录用户id
            ]),
        },
        //所有的方法
        methods: {
            getMsg(userId) {
                axios.get("http://localhost:8888/consumer/selectByPrimaryKey",{params: {id:userId}}).then(res=>{
                    console.log(res.data.avator)
                    this.avator = res.data.avator;
                    this.username = res.data.username;
                    if (res.data.sex ===0) {
                        this.userSex = "女";
                    } else if (res.data.sex===1) {
                        this.userSex = "男";
                    }
                    this.birth = this.attachBirth(res.data.birth);
                    this.location = res.data.location;
                    this.introduction = res.data.introduction;
                }).catch(err=>{
                    console.log(err)
                }
                )
                // getUserOfId(userId)
                //     .then((res) => {
                //         console.log(res)
                //         this.avator = res.avator;
                //         this.username = res.username;
                //         if (res.sex === 0) {
                //             this.userSex = "女";
                //         } else if (res.sex ===1) {
                //             this.userSex = "男";
                //         }
                //         this.birth = this.attachBirth(res.birth);
                //         this.location = res.location;
                //         this.introduction = res.introduction;
                //     })
                //     .catch((err) => {
                //         console.log(err);
                //     });
            },
            //获取我的收藏列表
            getCollection(userId) {
                axios.get("http://localhost:8888/collect/collectOfUserId",{params: {userId:userId}}).then(res=>{
                    this.collection = res.data;
                    //通过歌曲id获取歌曲信息
                    for (let item of this.collection) {
                        this.getSongsOfIds(item.songId);
                    }
                }).catch(err=>{
                        console.log(err)
                    }
                )
                ///collect/collectOfUserId?userId=
                // getCollectOfUserId(userId)
                //     .then((res) => {
                //         this.collection = res;
                //         //通过歌曲id获取歌曲信息
                //         for (let item of this.collection) {
                //             this.getSongsOfIds(item.songId);
                //         }
                //     })
                //     .catch((err) => {
                //         console.log(err);
                //     });
            },
            //通过歌曲id获取歌曲信息
            getSongsOfIds(id) {
                // songOfSongId(id)
                //     .then((res) => {
                //         this.collectList.push(res);
                //     })
                //     .catch((err) => {
                //         console.log(err);
                //     });
                // song/detail?songId=${id}
                axios.get("http://localhost:8888/song/detail",{params: {songId:id}}).then(res=>{
                    this.collectList.push(res.data);
                }).catch(err=>{
                        console.log(err)
                    }
                )
            },
        },
    }
</script>

<style lang="scss" scoped>
    // color
    $color-white: #ffffff;
    $color-white-dark: #f7f7f7;
    $color-grey: #8e98a2;
    $color-red: #e1594b;
    $color-blue: #26a2ff;
    $color-blue-dark: #48658f;
    $color-black: black;

    // distance
    $padding-out: 0 0.5em;
    ul, li {
        list-style-type: none;
        margin: 0;
        padding: 0;
    }

    /*@import "../assets/css/mui-btn.scss"*/
    /*@import "../assets/css/mine.scss"*/
    .mui-btn-block {
        font-size: 1em;
        display: block;
        width: 100%;
        margin: 1em auto 0 auto;
    }
    .mine {
        padding: 0.5em 1em 0 1em;
        text-align: left;
        .album-top {
            background: $color-white-dark;
            border-radius: 0.5em;
            position: relative;
            box-shadow: 0 0 0.5em #888888;
            margin-top: 1em;
            .album-img {
                width: 3em;
                position: absolute;
                top: -1em;
                left: 1em;
                img {
                    width: 100%;
                    height: 100%;
                    border-radius: 50%;
                }
            }
            .album-info {
                padding: 2em 1em 0.5em 1em;
                .info-name {
                    font-size: 1em;
                    position: absolute;
                    left: 5em;
                    font-weight: bold;
                    top: 0.1em;
                    color: $color-black;
                }
                .info-sex,
                .info-birth,
                .info-location,
                .info-signature {
                    font-size: 0.75em;
                    display: inline-box;
                    width: 100%;
                    color: $color-grey;
                }
            }
            .logout {
                position: absolute;
                top: 0;
                right: 1.25em;
                font-size: 1.25em;
                color: $color-grey;
            }
        }
        .album-content {
            background: $color-white;
            border-radius: 0.5em;
            position: relative;
            box-shadow: 0 0 0.5em #888888;
            margin-top: 1em;
            .album-content-title {
                font-size: 1em;
                color: $color-black;
                line-height: 1em;
                font-weight: bolder;
                padding-left: 1em;
                padding-top: 1em;
            }
        }
    }

    // 未登录样式
    .mui-table-view .mui-media,
    .mui-table-view .mui-media-body {
        line-height: 42px;
    }
    .mui-table-view-cell:after {
        left: 0px;
    }
    .member {
        margin-bottom: 15px;
        .header-con {
            padding: 10px;
            background-color: #fff;
            .user-info {
                position: relative;
                overflow: hidden;
                width: 100%;
                height: 120px;
                background: linear-gradient(90deg, #28a2ff, #ffd787);
                box-shadow: 0 0.1rem 0.25rem #f8e3c6;
                .avatar-con {
                    position: absolute;
                    left: 15px;
                    top: 50%;
                    transform: translateY(-50%);
                    .avatar {
                        width: 60px;
                        height: 60px;
                        overflow: hidden;
                        box-shadow: 0 2px 10px rgba(0, 0, 0, 15);
                        border: 1px solid hsla(0, 0%, 100%, 0.4);
                        border-radius: 50% 50%;
                        .image-info {
                            width: 100%;
                            height: 100%;
                        }
                    }
                }
                .person-con {
                    position: absolute;
                    left: 90px;
                    top: 50%;
                    transform: translateY(-50%);
                    color: #fff;
                }
            }
        }
    }

    .mui-media-body {
        text-align: left;
    }


</style>
